import Vue from 'vue';
import Router from 'vue-router';
/* Layout */
import Layout from '@/layout';

Vue.use(Router);

// this is common Routers
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }, {
    path: '/monitorPlus',
    name: 'monitorPlus',
    component: () => import('@/views/monitorPlus/index'),
    hidden: true
  },
  // this is the sideBar Router
  {
    path: '/',
    component: Layout,
    redirect: '/deviceManage/position',
    children: [{
      path: '/deviceManage/position',
      name: 'deviceManage_INFO_NOW',
      component: () => import('@/views/deviceManage/position/index'),
      meta: { title: 'INFO NOW', icon: 'tree' }
    }]
  },

  {
    path: '/deviceManage',
    component: Layout,
    name: 'deviceManage',
    meta: { title: '设备管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: '/deviceManage/list',
        name: 'deviceManage_list',
        component: () => import('@/views/deviceManage/list/index'),
        meta: { title: '设备列表', icon: 'table' }
      },

      {
        path: '/deviceManage/monitor',
        name: 'deviceManage_monitor',
        component: () => import('@/views/deviceManage/monitor/index'),
        meta: { title: '监控中心', icon: 'tree' }
      }, {
        path: '/deviceManage/position',
        name: 'deviceManage_position',
        component: () => import('@/views/deviceManage/position/index'),
        meta: { title: '设备位置', icon: 'tree' }
      }
    ]
  }
  , {
    path: '/powerManage',
    component: Layout,
    redirect: '/powerManage/institution',
    name: 'powerManage',
    meta: {
      title: '权限模块',
      icon: 'nested'
    },
    children: [
      {
        path: '/powerManage/institution',
        component: () => import('@/views/powerManage/institution/index'), // Parent router-view
        name: 'powerManage_institution',
        meta: { title: '组织管理' }
      },

      {
        path: '/powerManage/users',
        component: () => import('@/views/powerManage/users/index'),
        name: 'powerManage_users',
        meta: { title: '用户管理' }
      }

    ]
  }, {
    path: '/message',
    component: Layout,
    redirect: '/message',
    name: 'message',
    meta: {
      title: '信息发布',
      icon: 'nested'
    },
    children: [
      {
        path: '/message/contextPost',
        component: () => import('@/views/message/contextPost/index'),
        name: 'message_contextPost',
        meta: { title: '文本图片推送' }
      },
      {
        path: '/message/assetsPost',
        component: () => import('@/views/message/assetsPost/index'), // Parent router-view
        name: 'message_assetsPost',
        meta: { title: '信息推送' }

      }
    ]
  }, {

    path: '/history',
    component: Layout,
    redirect: '/history/community',
    name: 'history',
    meta: {
      title: '可视对讲',
      icon: 'nested'
    },
    children: [
      {
        path: '/deviceManage/chat',
        name: 'deviceManage_chat',
        component: () => import('@/views/deviceManage/chat/index'),
        meta: { title: '对讲与可视对讲', icon: 'tree' }
      }, {
        path: '/deviceManage/recorder',
        name: 'deviceManage_recorder',
        component: () => import('@/views/deviceManage/recorder/index'),
        meta: { title: '视频回放', icon: 'tree' }
      }
    ]
  },
  {
    path: '/audioRoom',
    name: 'audioRoom',
    component: () => import('@/views/deviceManage/chat/index')
  }, {
    path: '/systemLogManage',
    component: Layout,
    redirect: '/systemLogManage/log',
    children: [{
      path: '/systemLogManage/log',
      name: 'systemLogManage_log',
      component: () => import('@/views/systemLogManage/log/index'),
      meta: { title: '系统日志', icon: 'tree' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
];

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
